

package com.haoxi.gateway.smgpmsg;

import com.haoxi.gateway.util.TypeConvert;





public class SMGPMoRouteUpdateMessage extends SMGPMessage
{

    private StringBuffer strBuf;

    public SMGPMoRouteUpdateMessage(int updateType, int routeId, String srcGatewayId, String srcGatewayIP, int srcGatewayPort, String srcTermId)
        throws IllegalArgumentException
    {
        if(updateType < 0 || updateType > 255)
            throw new IllegalArgumentException(
            "The parameter of MoRouteUpdate message is wrong:UpdateType less than 0 or larger than 255.");
           
        if(srcGatewayId == null)
            throw new IllegalArgumentException(
            "The parameter of MoRouteUpdate message is wrong:SrcGatewayId value is null.");
            
        if(srcGatewayId.length() > 6)
            throw new IllegalArgumentException(
            "The parameter of MoRouteUpdate message is wrong:srcGatewayId length is larger than 8");
            
        if(srcGatewayIP == null)
            throw new IllegalArgumentException(
            "The parameter of MoRouteUpdate message is wrong:SrcGatewayIP value is null.");
            
        if(srcGatewayIP.length() > 15)
            throw new IllegalArgumentException(
            "The parameter of MoRouteUpdate message is wrong:SrcGatewayIP length is larger than 15");
           
        if(srcTermId == null)
            throw new IllegalArgumentException(
            "The parameter of MoRouteUpdate message is wrong:SrcTermId value is null.");
            
        if(srcTermId.length() > 21)
        {
            throw new IllegalArgumentException(
            "The parameter of MoRouteUpdate message is wrong:SrcTermId length is larger than 21");
            
        } else
        {
            int len = 61;
            buf = new byte[len];
            TypeConvert.int2byte(len, buf, 0);
            TypeConvert.int2byte(SMGPCommon.SMGP_MO_ROUTE_UPDATE, buf, 4);
            buf[12] = (byte)updateType;
            TypeConvert.int2byte(routeId, buf, 13);
            System.arraycopy(srcGatewayId.getBytes(), 0, buf, 17, srcGatewayId.length());
            System.arraycopy(srcGatewayIP.getBytes(), 0, buf, 23, srcGatewayIP.length());
            TypeConvert.short2byte(srcGatewayPort, buf, 38);
            System.arraycopy(srcTermId.getBytes(), 0, buf, 40, srcTermId.length());
            strBuf = new StringBuffer(300);
            strBuf.append(",updateType=".concat(String.valueOf(String.valueOf(updateType))));
            strBuf.append(",RouteID=".concat(String.valueOf(String.valueOf(routeId))));
            strBuf.append(",SrcGatewayID=".concat(String.valueOf(String.valueOf(srcGatewayId))));
            strBuf.append(",SrcGatewayIP=".concat(String.valueOf(String.valueOf(srcGatewayIP))));
            strBuf.append(",SrcGatewayPort=".concat(String.valueOf(String.valueOf(srcGatewayPort))));
            strBuf.append(",SrcTermId=".concat(String.valueOf(String.valueOf(srcTermId))));
            return;
        }
    }

    public String toString()
    {
        StringBuffer outStr = new StringBuffer(300);
        outStr.append("SMGPMtRouteUpdateMessage:");
        outStr.append("PacketLength=".concat(String.valueOf(String.valueOf(buf.length))));
        outStr.append(",RequestID=9");
        outStr.append(",Sequence_Id=".concat(String.valueOf(String.valueOf(getSequenceId()))));
        if(strBuf != null)
            outStr.append(strBuf.toString());
        return outStr.toString();
    }

    public int getRequestId()
    {
        return SMGPCommon.SMGP_MO_ROUTE_UPDATE;
    }
}
